from playwright.sync_api import Playwright, sync_playwright


def run(playwright: Playwright) -> None:
    browser = playwright.firefox.launch(headless=False)
    context = browser.new_context()

    # Open new page
    page = context.new_page()

    # Go to https://www.baidu.com/
    page.goto("https://www.baidu.com/")

    # Click input[name="wd"]
    page.click("input[name=\"wd\"]")

    # Fill input[name="wd"]
    page.fill("input[name=\"wd\"]", "goto")

    # Press Enter
    # with page.expect_navigation(url="https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd=goto&fenlei=256&rsv_pq=c233c5ba000225b5&rsv_t=fab1SpD%2B1uiItFAfTyUuN%2BI6ToWUqpzgIS5d0WpwxzPCEsjx1kB9O47tBzc&rqlang=cn&rsv_enter=1&rsv_dl=tb&rsv_sug3=5&rsv_sug1=3&rsv_sug7=100&rsv_sug2=0&rsv_btype=i&prefixsug=goto&rsp=5&inputT=5&rsv_sug4=4667"):
    with page.expect_navigation():
        page.press("input[name=\"wd\"]", "Enter")

    # Click text=goto - 百度翻译
    page.click("text=goto - 百度翻译")

    # Click text=goto语句 - 百度百科
    page.click("text=goto语句 - 百度百科")

    # ---------------------
    context.close()
    browser.close()


with sync_playwright() as playwright:
    run(playwright)
